package com.example.service;

import com.example.entity.User;
import com.example.exception.CustomException;
import com.example.mapper.UserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserService {
    @Resource
    private UserMapper userMapper;
    public User login(User user) {
        String username = user.getUsername();
        User dbuser = userMapper.selectbyusername(username);
        if(dbuser == null) {
            throw new CustomException("500","账户不存在");
        }
        String password = user.getPassword();
        if (!dbuser.getPassword().equals(password)){
            throw new CustomException("500","账号或密码错误");
        }
        return dbuser;
    }
}
